#include "equipmentshop.h"
#include "ui_equipmentshop.h"
#include<QWidget>
#include<QLabel>
#include<QKeyEvent>
#include<QPixmap>
#include<QPushButton>
#include<qrect.h>
#include<QFont>
#include"menu.h"
#include <QDebug>
#include<QTime>
#include<ctime>
#include"mainwindow.h"
Equipmentshop::Equipmentshop()
{
    saltstore=2;
    money=50;
    shengmustore=2;
    takeawayshengmu=0;
    //生成各种按钮的界面
    takeawayshengmu=0;
    this->setGeometry(435,100,700,700);
    startRealgameButton=new QPushButton("前往鬼房",this);
    startRealgameButton->move(590,580);
    startRealgameButton->resize(100,50);
    //关于圣木的按钮
    buyshengmu=new QPushButton("+",this);
    buyshengmu->move(330,90);
    buyshengmu->resize(31,31);
    B_increasetakeawayshengmu=new QPushButton("+",this);
    B_increasetakeawayshengmu->move(330,130);
    B_increasetakeawayshengmu->resize(31,31);
    B_reducetakeawayshengmu=new QPushButton("-",this);
    B_reducetakeawayshengmu->move(370,130);
    B_reducetakeawayshengmu->resize(31,31);
    //关于盐的按钮
    buysalt=new QPushButton("+",this);
    buysalt->move(330,240);
    buysalt->resize(31,31);
    increasesalt=new QPushButton("+",this);
    increasesalt->move(330,280);
    increasesalt->resize(31,31);
    reducesalt=new QPushButton("-",this);
    reducesalt->move(370,280);
    reducesalt->resize(31,31);
    timer1=new QTimer(this);//设定计时器
    timer1->start(100);
    setFixedSize(700,700);
    setWindowTitle("装备车");
    connect(timer1,SIGNAL(timeout()),this,SLOT(Equipmentshop_update()));
    connect(B_reducetakeawayshengmu,&QPushButton::clicked,this,&Equipmentshop::reducetakeawayshengmu);//连接减少带走圣母
    connect(B_increasetakeawayshengmu,&QPushButton::clicked,this,&Equipmentshop::increasetakeawayshengmu);//连接增加带走圣母
    connect(buyshengmu,&QPushButton::clicked,this,&Equipmentshop::increaseshengmu);//连接增加仓库圣木
    connect(startRealgameButton,&QPushButton::clicked,this,&Equipmentshop::startrealgame);//连接开始游戏
    connect(reducesalt,&QPushButton::clicked,this,&Equipmentshop::reducenumbersalttaken);
    connect(increasesalt,&QPushButton::clicked,this,&Equipmentshop::increasenumbersalttaken);
    connect(buysalt,&QPushButton::clicked,this,&Equipmentshop::increase_salt);
}
Equipmentshop::Equipmentshop(int moneynumber,int shengmustore1)
{
    //生成各种按钮的界面
    takeawayshengmu=0;
    this->setGeometry(435,100,700,700);
    startRealgameButton=new QPushButton("前往鬼房",this);
    startRealgameButton->move(590,580);
    startRealgameButton->resize(100,50);
    //关于圣木的按钮
    buyshengmu=new QPushButton("+",this);
    buyshengmu->move(330,90);
    buyshengmu->resize(31,31);
    B_increasetakeawayshengmu=new QPushButton("+",this);
    B_increasetakeawayshengmu->move(330,130);
    B_increasetakeawayshengmu->resize(31,31);
    B_reducetakeawayshengmu=new QPushButton("-",this);
    B_reducetakeawayshengmu->move(370,130);
    B_reducetakeawayshengmu->resize(31,31);
    //关于盐的按钮
    buysalt=new QPushButton("+",this);
    buysalt->move(330,240);
    buysalt->resize(31,31);
    increasesalt=new QPushButton("+",this);
    increasesalt->move(330,280);
    increasesalt->resize(31,31);
    reducesalt=new QPushButton("-",this);
    reducesalt->move(370,270);
    reducesalt->resize(31,31);
    timer1=new QTimer(this);//设定计时器
    timer1->start(100);
    setFixedSize(700,700);
    setWindowTitle("装备车");
    connect(timer1,SIGNAL(timeout()),this,SLOT(Equipmentshop_update()));
    connect(B_reducetakeawayshengmu,&QPushButton::clicked,this,&Equipmentshop::reducetakeawayshengmu);//连接减少带走圣母
    connect(B_increasetakeawayshengmu,&QPushButton::clicked,this,&Equipmentshop::increasetakeawayshengmu);//连接增加带走圣母
    connect(buyshengmu,&QPushButton::clicked,this,&Equipmentshop::increaseshengmu);//连接增加仓库圣木
    connect(startRealgameButton,&QPushButton::clicked,this,&Equipmentshop::startrealgame);//连接开始游戏
    connect(reducesalt,&QPushButton::clicked,this,&Equipmentshop::reducenumbersalttaken);
    connect(increasesalt,&QPushButton::clicked,this,&Equipmentshop::increasenumbersalttaken);
    connect(buysalt,&QPushButton::clicked,this,&Equipmentshop::increase_salt);
    money=moneynumber;
    shengmustore=shengmustore1;
    saltstore=2;
}
//Equipmentshop::~Equipmentshop()
//{
//    delete ui;
//}
//void Equipmentshop::paintEvent(QPaintEvent*event)
//{

//}
void Equipmentshop::keyPressEvent(QKeyEvent *event)
{
    QKeyEvent *key=(QKeyEvent*)event;
    switch(key->key())
    {
    case Qt::Key_Escape:
        //emit sendsignal();
        this->hide();
        menu1->show();
        break;
    }
}
void Equipmentshop::startrealgame()
{
    this->hide();
    MainWindow *ui_mainwindow=new MainWindow(money,takeawayshengmu,shengmustore,salt);
    ui_mainwindow->equipmentshop1=this;
    ui_mainwindow->show();
}
void Equipmentshop::paintEvent(QPaintEvent*event)
{
    QPainter painter(this);
    QFont font1("Micro soft YaHei UZ",15);
    painter.setFont(font1);
    painter.setPen(Qt::black);
    painter.setBrush(Qt::black);
    painter.drawText(240,60,"圣木");
    painter.drawText(240,100,"库存");
    painter.drawText(240,140,"装备");
    painter.drawText(290,60,"10RMB");
    painter.drawText(290,100,QString::number(shengmustore));
    painter.drawText(290,140,QString::number(takeawayshengmu));
    painter.drawText(100,20,QString::number(money));
    painter.drawText(10,20,"金币数量");
    painter.drawText(240,210,"盐");
    painter.drawText(240,250,"库存");
    painter.drawText(240,290,"装备");
    painter.drawText(290,210,"15RMB");
    painter.drawText(290,250,QString::number(saltstore));
    painter.drawText(290,290,QString::number(salt));

}
void Equipmentshop::increaseshengmu()
{
    if(money<10)
        return;
    else
     {
        money=money-10;
        shengmustore=shengmustore+1;
     }
}
void Equipmentshop::increasetakeawayshengmu()
{
    if(takeawayshengmu+1>6||takeawayshengmu+1>shengmustore)
        return;
    else
    {
        takeawayshengmu++;
    }
}
void Equipmentshop::reducetakeawayshengmu()
{
    if(takeawayshengmu-1<0)
        return;
    else
    {
        takeawayshengmu--;
    }
}

void Equipmentshop::increase_salt()
{
    if(money<15)
        return;
    else
    {
        money=money-15;
        saltstore=saltstore+1;
    }
}
void Equipmentshop::reducenumbersalttaken()
{
    if(salt>0)
    {
        salt =salt-1;
    }
}
void Equipmentshop::increasenumbersalttaken()
{
    if(salt<4&&salt<saltstore)
    {
        salt=salt+1;
    }
}




















void Equipmentshop::Equipmentshop_update()
{
    update();
}

